<!--
 * @Author: Penk
 * @LastEditors: Penk
 * @LastEditTime: 2022-11-14 12:07:39
 * @FilePath: \web面试题\变量提升以及作用域.html
 * @email: 492934056@qq.com
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 变量提升，指的是变量声明的提升，不是值赋值~
      console.log("a: ", a);
      var a = "a";

      // 作用域
      // 全局作用域 函数作用域 块级作用域
      var globalVar = "global";
      function fn() {
        var fnVar = "fn";
      }

      // arguments
      function foo(a, b, c) {
        console.log(arguments.length);
        arguments[1] = 12;
        console.log(arguments[1]);
      }

      var a = 1;
      var b = 2;
      foo(a, b);
      console.log(b);

      //
      function foo(obj) {
        console.log(obj.a);
        obj.a = 2;
        console.log(obj.a);
      }
      var obj = { a: 1 };
      foo(obj);
      console.log("obj.a:", obj.a);
    </script>
  </body>
</html>
